//var domain = 'http://zns.wan.com';
var flag = false;

$(function () {

    $("#login").click(function () {
        if (!flag) {
            var username = $("#username").val();
            var password = $("#password").val();
            if (username == '') {
                alert("用户名不能为空！");
                return;
            }
            if (password == '') {
                alert("密码不能为空！");
                return;
            }
            var param = 's=user/login&username=' + username + "&password=" + password
            $.ajax({
                type: 'get',
                url: domain + '/index.php',
                data: param,
                dataType: 'jsonp',
                success: function (data) {
                    if(data['ret']==0){
                        window.location.reload();
                    }else{
                        alert(data['msg']);
                    }
                },
                error: function (data) {
                    flag = false;
                    alert('网络忙，请稍后在试！');
                }
            });

        } else {
            return;
        }
    });
    if (check_login()) {
        $("#user_log_name").text($.cookie('webgame'));
        $("#before_login").hide();
        $("#after_login").show();
    } else {
        $("#before_login").show();
        $("#after_login").hide();
    }
});


function check_login() {
    if ($.cookie('webgame')) {
        return 1;
    } else {
        return 0;
    }
}